//@author A0105546J

package tasky.tests;
import static org.junit.Assert.assertTrue;

import java.util.ArrayList;

import org.junit.Test;

import tasky.commons.Task;
import tasky.history.History;
import tasky.history.HistoryStatus;


public class HistoryTest {

	@Test
	public void test() {
		
		//Test storeUndo. Please first change "undoStack" in History to be public. After the test, please change it back to be private.
		
		History h = new History();
		
		ArrayList<Task> listA = new ArrayList<Task>();
		listA.add(new Task("a"));
		ArrayList<Task> listB = new ArrayList<Task>();
		listB.add(new Task("b"));
		ArrayList<Task> listC = new ArrayList<Task>();
		listC.add(new Task("c"));
		
		h.storeUndo(listA, "add");
		assertTrue(h.undoStack.peek().getTasks().get(0).getContent().equals("a"));
		assertTrue(h.undoStack.peek().getCommand().equals("add"));
		
		h.storeUndo(listB, "edit");
		assertTrue(h.undoStack.peek().getTasks().get(0).getContent().equals("b"));
		assertTrue(h.undoStack.peek().getCommand().equals("edit"));
		
		h.storeUndo(listC, "delete");
		assertTrue(h.undoStack.peek().getTasks().get(0).getContent().equals("c"));
		assertTrue(h.undoStack.peek().getCommand().equals("delete"));
		
		h.undoStack.pop();
		
		assertTrue(h.undoStack.peek().getTasks().get(0).getContent().equals("b"));
		assertTrue(h.undoStack.peek().getCommand().equals("edit"));
		
		h.undoStack.pop();
		
		assertTrue(h.undoStack.peek().getTasks().get(0).getContent().equals("a"));
		assertTrue(h.undoStack.peek().getCommand().equals("add"));
		
		h.undoStack.pop();
		
		assertTrue(h.undoStack.size() == 0);
		
		//End of test for storeUndo. Please change "undoStack" back to be private.
		
		
		
		//Test Undo.
		
		h = new History();
		
		assertTrue(h.undo(listA) == null);
		
		h.storeUndo(listA, "add");
		h.storeUndo(listB, "edit");
		
		HistoryStatus testHS;
		
		testHS = h.undo(new ArrayList<Task>());
		
		assertTrue(testHS.getCommand().equals("edit"));
		assertTrue(testHS.getTasks().get(0).getContent().equals("b"));
		
		testHS = h.undo(new ArrayList<Task>());
		
		assertTrue(testHS.getCommand().equals("add"));
		assertTrue(testHS.getTasks().get(0).getContent().equals("a"));
		
		testHS = h.undo(new ArrayList<Task>());
		
		assertTrue(h.undo(listA) == null);
		
		//End of test for Undo. 
		
		
		//Test Redo.
		
		h = new History();
		
		assertTrue(h.redo(listA) == null);
		
		h.storeUndo(listA, "add");
		h.storeUndo(listB, "edit");
		
		h.undo(new ArrayList<Task>());
		h.undo(new ArrayList<Task>());
		
		testHS = h.redo(new ArrayList<Task>());
		
		assertTrue(testHS.getCommand().equals("add"));
		
		testHS = h.redo(new ArrayList<Task>());
		
		assertTrue(testHS.getCommand().equals("edit"));
		
		assertTrue(h.redo(new ArrayList<Task>()) == null);
		
		//End of test for Redo.
		
		
	}
	
	
}
